package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enums.AutoFillType;
import com.sky.vo.DishPageQueryItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.StatusCountVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    @AutoFill(type = AutoFillType.INSERT)
    int insert(Dish dish);

    Page<DishPageQueryItemVO> page(DishPageQueryDTO dto);

    Dish selectById(Long id);

    int deleteById(Long id);

    DishVO selectByIdWithFlavors(Long id);

    @AutoFill(type = AutoFillType.UPDATE)
    void update(Dish dish);

    /**
     * 动态条件查询菜品
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);

    /**
     * 根据套餐id查询菜品
     * @param setmealId
     * @return
     */
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);

    @Select("select count(*) count, status from dish group by status")
    List<StatusCountVO> groupCountByStatus();
}
